package com.rsk.api;


import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysCompanysService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.QueryParam;
import java.util.List;
import java.util.Map;

/**
 * 后台机构
 * @author myr
 */

@RestController
@RequestMapping(value="/sys/company")
public class SysCompanysApi {

    @Reference(interfaceClass = SysCompanysService.class, protocol = "dubbo")
    private SysCompanysService sysCompanysService;

    /**
     * 删除后台机构
     * @param id
     * @param Authorization
     * @return
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/delSysCompanys" )
    public Result<String> delSysCompanys(@QueryParam("id") Long id,
                                          @RequestHeader("Authorization") String Authorization){
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanysService.delSysCompanys(id, operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }

    /**
     * 查询后台机构
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/selectSysCompanys")
    public Result<List<Map>> selectSysCompanys(@QueryParam("companyAttribute")Long companyAttribute,
                                               @QueryParam("companyName")  String companyName,
                                               @QueryParam("companyTypeId") Long companyTypeId,
                                               @QueryParam("nowPage") Integer nowPage,
                                               @QueryParam("pageSize") Integer pageSize,
                                               @RequestHeader("Authorization") String Authorization){

        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        List<Map> maps = sysCompanysService.selectSysCompanys(companyAttribute,companyName,companyTypeId,nowPage,pageSize);
        return ResultBuilder.success(maps,ResultCode.SUCCESS);
    }

    /**
     * 新增后台机构
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/saveSysCompanys")
    public Result<String> saveSysCompanys(
                                          @QueryParam("companyName") String companyName,
                                          @QueryParam("companyTypeId") String companyTypeId,
                                          @QueryParam("companyAttribute") Long companyAttribute,
                                          @QueryParam("companyCode") String companyCode,
                                          @RequestHeader("Authorization") String Authorization){

        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanysService.saveSysCompanys(companyName,companyTypeId,companyAttribute,companyCode,operatorUser);
        return ReturnUtils.returnDataByOne(i);

    }

}
